Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First weekend final version #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TonyGriffin
Copy link

No description provided.


const menu = {
1 : {
id: Math.floor(Math.random() * (max - min + 1)) + min,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense to use the same id as was used for the key here. Otherwise we end up with inconsistent ids on every executing. Also, by using random we run the risk of duplicate ids which may cause strange bugs


// #3 Works
getMenuItem(id) {
const foodItem = Object.values(menu).find( item => item.id === parseInt(id));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using ids as keys in menu object, we can get individual menu items using menu[id]

if (result) {
res.json(result);
} else {
res.status(404).send('The food item with the given ID was not found');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would better the send the error message as JSON so that it can be read by fetch the same way as normal result. Otherwise, the front end will throw an error when it tries to convert a string to object.

@@ -0,0 +1,90 @@

orderList = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to store orders as an object rather than as an array so we can look up orders easily using ids



getFetch() {
const serverFetch = `http://localhost:8080/menu`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would better use relative url here /menu as that would allow the code to work when app is deployed to server with another url

}


getFetch() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getFetch is a little ambiguous, something like fetchMenu would work better as its more descriptive of the function behaviour


const min = 1;
const max = 100;
let keyId = Math.floor(Math.random() * (max - min + 1)) + min;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would better to generate sequential ids on server to avoid potential duplicates that can result from random generation or multiple users generating same id

const newTotalPrice = Number(this.state.totalPrice) + order.price;
console.log("newTotalPrice",newTotalPrice);
this.setState( {
currentOrder : order,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear how currentOrder is used. It is initialised as an array, but get's an object set in it. Also it looks like currentOrder is not used in the application

@dmitrigrabov
Copy link
Contributor

Good work. There are few bits that need a little tidying up, but overall it looks like a great start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants